package br.ufc.vv.dao;

import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.Transaction;

import br.ufc.vv.model.ProcessoVotacao;
import br.ufc.vv.util.HibernateUtil;

public class ProcessoVotacaoDao {

	
	public void save(ProcessoVotacao votacao){
		Session session = HibernateUtil.getSession();
		Transaction transacao = session.beginTransaction();
		try {
			session.save(votacao);
			transacao.commit();
		} catch (Exception e) {
			transacao.rollback();
		} finally {
			session.close();
		}	
	}
	
	
	public void update(ProcessoVotacao votacao){
		Session session = HibernateUtil.getSession();
		Transaction transacao = session.beginTransaction();
		try {
			session.update(votacao);
			transacao.commit();
		} catch (Exception e) {
			transacao.rollback();
		} finally {
			session.close();
		}	
	}
	
	public void delete(ProcessoVotacao votacao){
		Session session = HibernateUtil.getSession();
		Transaction transacao = session.beginTransaction();
		try {
			session.delete(votacao);
			transacao.commit();
		} catch (Exception e) {
			transacao.rollback();
		} finally {
			session.close();
		}	
	}
	
	public List<ProcessoVotacao> list(){
		Session session = HibernateUtil.getSession();
		try {
			Criteria c = session.createCriteria(ProcessoVotacao.class);
			return c.list();
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			session.close();
		}
		return null;
	}

	public ProcessoVotacao get(Long id) {
		Session session = HibernateUtil.getSession();
			return (ProcessoVotacao) session.get(ProcessoVotacao.class, id);
		
	}

}
